home *** CD-ROM | disk | FTP | other *** search
- #include "lack.h"
- #include "vaproto.h"
- #include <string.h>
- #include <mintbind.h>
- #include <memory.h>
- extern char *getenv(char *);
- char **environ;
-
- ki;
- extern int apid;
- extern int aes_version;
- extern int get_menu_title;
- extern lap *lapps[];
- extern lap *curapp;
-
- /* fs.c: */
- long launch_prg(char *name, char *args);
-
- /* trap2.c: */
- void get_gem_stack(void);
- int check_for_desk(int was_desk);
- int install_trap2(void);
-
- struct name_mess
- {
- int type;
- int from;
- int length;
- char *name;
- int domain;
- int prg;
- };
-
- #define LACK_ITEM " you lack an acc "
- #define CONT_ITEM " Lack Control "
- #define TIMER 200
- /* milliseconds between lackontrol's evnt_multi calls, this _really_ slows
- * things down right now, so a larger value may be preferred */
-
- const char *globs[2][2]={"*.AC?", "*.ac?", "*.PRG", "*.prg"};
- const char *prompts[2][2]={"ackessory to load",
- "MiNT domain ackessory to load",
- "program to load",
- "program to load"
- };
-
- const char kill_string[]=" kill acc:";
-
- OBJECT rs_object[] = {
- -1, 1, 5, G_BOX, NONE, NORMAL, 0xff1100L, 0,0, 22,5,
- 2, -1, -1, G_STRING, NONE, DISABLED, (long)kill_string, 0,0, 22,1,
- 3, -1, -1, G_STRING, NONE, NORMAL, 0x1L, 0,1, 22,1,
- 4, -1, -1, G_STRING, NONE, NORMAL, 0x2L, 0,2, 22,1,
- 5, -1, -1, G_STRING, NONE, NORMAL, 0x3L, 0,3, 22,1,
- 6, -1, -1, G_STRING, NONE, NORMAL, 0x4L, 0,4, 22,1,
- 0, -1, -1, G_STRING, LASTOB, NORMAL, 0x5L, 0,5, 22,1};
- #define NUM_OBJ 7
- #define FIRST_SLOT 2
- #define LAST_SLOT 6
-
- int deskx, desky, deskw, deskh;
- int charw, charh, boxw, boxh;
-
- int
- popup(MENU_T *me_menu, int me_xpos, int me_ypos, MENU_T *me_mdata)
- {
- OBJECT *tree=me_menu->mn_tree;
- int start=me_menu->mn_menu;
- int width, height, handle;
- int mousex, mousey, keystate;
- int event, m1_flag, m1_x, m1_y, m1_w, m1_h;
- int junk, cur_obj=0, old_obj=0;
- int oldx, oldy;
-
- width=tree[start].ob_width;
- height=tree[start].ob_height;
- oldx=tree[start].ob_x;
- oldy=tree[start].ob_y;
- if((me_xpos + width) > (deskx + deskw)) me_xpos=deskx + deskw - width;
- if((me_ypos + height) > (desky + deskh)) me_ypos=desky + deskh - height;
- if(me_xpos < deskx) me_xpos=deskx;
- if(me_ypos < desky) me_ypos=desky;
- tree[start].ob_x=me_xpos;
- tree[start].ob_y=me_ypos;
- wind_update(BEG_MCTRL);
- form_dial(FMD_START, me_xpos - 1, me_ypos -1, width + 2, height + 2,
- me_xpos - 1, me_ypos -1, width + 2, height + 2);
- objc_draw(tree, start, 1, me_xpos - 1, me_ypos -1, width + 2, height + 2);
- graf_mkstate(&mousex, &mousey, &junk, &junk);
- event=MU_M1;
- while(1)
- {
- if(event & MU_M1)
- {
- if(cur_obj) /* deselect old cur_obj */
- objc_change(tree, cur_obj, 0, me_xpos, me_ypos, width, height,
- tree[cur_obj].ob_state ^ SELECTED, 1);
- old_obj=cur_obj;
- cur_obj=objc_find(tree, start, 1, mousex, mousey);
- if(cur_obj==-1)
- {
- m1_flag=0;
- m1_x=me_xpos;
- m1_y=me_ypos;
- m1_w=width;
- m1_h=height;
- cur_obj=0;
- }else{
- m1_flag=1;
- m1_x=me_xpos+tree[cur_obj].ob_x;
- m1_y=me_ypos+tree[cur_obj].ob_y;
- m1_w=tree[cur_obj].ob_width;
- m1_h=tree[cur_obj].ob_height;
- if(tree[cur_obj].ob_state & DISABLED) cur_obj=0;
- else objc_change(tree, cur_obj, 0, me_xpos, me_ypos, width, height,
- tree[cur_obj].ob_state | SELECTED, 1);
- }
- }
- if(event & MU_BUTTON) break;
- event=evnt_multi(MU_BUTTON | MU_M1,
- 1, 1, 1, /* mouse clicks, should allow pull down */
- m1_flag, m1_x, m1_y, m1_w, m1_h,
- 0, 0, 0, 0, 0, /* mouse rect 2, do submenu */
- (void *)0, /* mesag */
- 0L, /* timer */
- &mousex, &mousey,
- &junk, &keystate,/* button state, keystate */
- &junk, &junk /* keycode, number button events */
- );
- }
- if(me_menu != me_mdata) *me_mdata=*me_menu;
- me_mdata->mn_item=cur_obj;
- me_mdata->mn_keystate=keystate;
- tree[start].ob_x=oldx;
- tree[start].ob_y=oldy;
- if(cur_obj) tree[cur_obj].ob_state ^= SELECTED;
- form_dial(FMD_FINISH, me_xpos - 1, me_ypos -1, width + 2, height + 2,
- me_xpos - 1, me_ypos -1, width + 2, height + 2);
- wind_update(END_MCTRL);
- return (cur_obj ? 1 : 0);
- }
-
- typedef struct __acc_menu
- {
- int apid;
- int obj;
- struct __acc_menu *next;
- }acc_menu;
-
- kill_acc_menu(myid)
- {
- int i, cur_obj=FIRST_SLOT-1;
- int x, y, junk;
- int old_next, old_height;
- MENU_T men={rs_object, 0, 1, 0, 0};
- acc_menu *accs, *end;
- int mess[8]={AC_OPEN, myid, 0, 0, 0, 0, 0, 0};
-
- accs=end=alloca(sizeof(acc_menu));
- accs->obj=0;
- for (i=myid - 1; i>=2; i--)
- {
- if(lapps[i])
- if(!lapps[i]->acc->free)
- {
- end->next=alloca(sizeof(acc_menu));
- end=end->next;
- end->apid=i;
- end->obj=++cur_obj;
- rs_object[cur_obj].ob_spec=(long)&lapps[i]->acc->menu_title;
- }
- }
- old_next=rs_object[cur_obj].ob_next;
- rs_object[cur_obj].ob_next = 0;
- rs_object[0].ob_tail=cur_obj;
- old_height=rs_object[0].ob_height;
- rs_object[0].ob_height=charh * (cur_obj - FIRST_SLOT + 2);
- graf_mkstate(&x, &y, &junk, &junk);
- if(popup(&men, x, y, &men))
- {
- while(accs->obj < men.mn_item) accs=accs->next;
- if(accs->obj != men.mn_item)
- form_alert(1, "[3][can't find selected item][ oh shit ]");
- else{
- lapps[accs->apid]->action=APPL_KILL;
- appl_write(accs->apid, 16, mess);
- }
- }
- rs_object[cur_obj].ob_next=old_next;
- rs_object[0].ob_tail=LAST_SLOT;
- rs_object[0].ob_height=old_height;
- }
-
- int
- start_acc(char *name, int dom, int prgflag)
- {
- int to_pid=2;
- struct name_mess mess={LA_LOAD_ACC, apid, 0, name, dom, prgflag};
-
- for(;to_pid<NUM_APPS; to_pid++)
- if(lapps[to_pid] && lapps[to_pid]->acc)
- if(lapps[to_pid]->acc->free)
- break;
- if(to_pid==NUM_APPS)
- {
- form_alert(1, "[0][lack: no empty acc slots][ Bobdammit! ]");
- return -1;
- }
- lapps[to_pid]->acc->free=FALSE;
- appl_write(to_pid, 16, (int *)&mess);
- mess.type=AC_OPEN;
- ((int *)&mess)[3]=lapps[to_pid]->acc->menu_index;
- appl_write(to_pid, 16, (int *)&mess);
- }
-
- void
- interface(BASEPAGE *b)
- {
- NEW_AESP(a);
- lap *me;
- struct lacc *acc;
- int c, ok=1;
- int keys, r, junk; /* evnt_multi stuff */
- int mydom, dom, prg;
- struct name_mess mess;
- char first_path[128];
- char *path;
- char *end_first_path=&first_path[0];
- char fname[33];
-
-
- apid=cur_apid;
- me=curapp;
- acc=me->acc;
- Syield(); Syield();
- Pdomain(0);
- environ=(char **)Dcntl(LA_BUILD_ENV, "S:", b->p_env);
- get_gem_stack();
- _aesparams=&a;
- install_trap2();
- apid=appl_init();
- aes_version=a.global[0];
- if(cur_apid != apid)
- form_alert(0,"[3][lack: I can't find gem's|current application structure][ anything but that ]");
- aes_version=a.global[0];
- strncpy(acc->myname, aes_appl->name, 8);
- acc->free=FALSE;
- strcpy(acc->menu_title, CONT_ITEM);
- get_menu_title=TRUE;
- acc->menu_index=menu_register(apid, acc->menu_title);
- get_menu_title=FALSE;
-
- graf_handle(&charw, &charh, &boxw, &boxh);
- wind_get(0, WF_WORKXYWH, &deskx, &desky, &deskw, &deskh);
- rsrc_saddr(R_OBJECT, 0, (char *)&rs_object[0]);
- for(c=0; c< NUM_OBJ; c++)
- rsrc_obfix(rs_object, c);
-
- bzero(first_path, 128);
- bzero(fname, 33);
- path=getenv("PATH");
- if(!path)
- if(!shel_envrn(&path, "PATH=")) path=NULL;
- if(path)
- {
- /* it is always a good idea to keep gem programs in the first
- * directory of the path, so this is the default place to find
- * acc's.
- */
- if(*path=='/')
- /* I cannot believe tcsh leaves the PATH in this format!! */
- {
- end_first_path=strcpy(first_path, "U:");
- end_first_path+=2;
- while(*path != ':' && *path != ',' && *path != ';')
- {
- if(*path=='/')
- {
- *end_first_path++='\\';
- path++;
- }else *end_first_path++ = *path++;
- }
- }else
- while(*path != ',' && *path != ';') *end_first_path++ = *path++;
- if(*(end_first_path-1)!='\\') *end_first_path++='\\';
- }else{ /* no damn path anywhere */
- strcpy(first_path, "U:\\");
- end_first_path=first_path+3;
- }
-
- while(1)
- {
- r=evnt_multi(MU_MESAG | MU_TIMER | MU_M1,
- 0, 0, 0, /* mouse button */
- 0, 0, 16, 1, 1,/* mouse rect 1 */
- 0, 0, 0, 0, 0, /* mouse rect 2 */
- (int *)&mess, /* message buf */
- TIMER, /* timer */
- &junk, &junk, /* mouse pos */
- &junk, /* mouse buttons*/
- &keys, /* keyshift */
- &junk, &junk /* keycode and number of mouse clicks */
- );
- if(r & MU_MESAG)
- {
- switch(mess.type)
- {
- case AC_OPEN:
- if(keys & 4) kill_acc_menu(apid);
- else{
- mydom=Pdomain(-1);
- dom=(keys & 3)? 1 : 0;
- prg=(keys & 8)? 1 : 0;
- strcpy(end_first_path, globs[prg][mydom]);
- wind_update(BEG_UPDATE);
- wind_update(BEG_MCTRL);
- fsel_exinput(first_path, fname, &ok, prompts[prg][dom]);
- wind_update(END_UPDATE);
- wind_update(END_MCTRL);
- end_first_path=first_path+strlen(first_path);
- while(*(end_first_path - 1) != '\\') end_first_path--;
- strcpy(end_first_path, fname);
- if(ok) start_acc(first_path, dom, prg);
- }
- break;
- case AC_CLOSE:
- {
- long ssp;
-
- /*appl_yield();*/ evnt_timer(20);
- ssp=Super(0);
- check_for_desk(FALSE);
- Super(ssp);
- break;
- }
- case VA_START:
- start_acc(mess.name, 0, 0); break;
- }
- }
- }
- }
-
- void
- empty_acc(BASEPAGE *b)
- {
- NEW_AESP(a);
- struct name_mess mess;
- lap *me;
- struct lacc *acc;
- int ret;
-
- Syield(); Syield(); /* let the caller wake up */
- get_gem_stack();
- _aesparams=&a;
- me=curapp;
- acc=me->acc;
- acc->free=TRUE;
- appl_init();
- strncpy(acc->myname, aes_appl->name, 8);
- strcpy(acc->menu_title, LACK_ITEM);
- get_menu_title=TRUE;
- acc->menu_index=menu_register(apid, acc->menu_title);
- get_menu_title=FALSE;
-
- while(1)
- {
- evnt_mesag((int *)&mess);
- if(mess.type==LA_LOAD_ACC)
- {
- acc->free=FALSE;
- if(mess.prg)
- {
- acc->isprg=TRUE;
- ret=launch_prg(mess.name, "");
- acc->isprg=FALSE;
- graf_mouse(0, 0);
- }else{
- Pdomain(mess.domain);
- ret=(short)Dcntl(LA_LOAD_ACC, "S:", mess.name);
- }
- if (ret<0) form_alert(1,"[1][lack: error starting acc][ huh ]");
- acc->free=TRUE;
- _aesparams=&a;
- strncpy(aes_appl->name, acc->myname, 8);
- strcpy(acc->menu_title, LACK_ITEM);
- }
- }
- }
-